package com.example.administrator.jingpingou.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.jingpingou.R;
import com.example.administrator.jingpingou.bean.TeJiaBean;
import com.example.administrator.jingpingou.config.NetConfig;
import com.example.administrator.jingpingou.netinteface.NetInterface;
import com.example.administrator.jingpingou.ui.TeJiaDetailActivity;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/8/29 0029.
 */
public class TeJiaAdapterOne extends RecyclerView.Adapter<TeJiaAdapterOne.MyViewHolder> {
    private List<TeJiaBean.ListEntity> mData;
    private Context mContext;
    private ImageOptions options;

    public TeJiaAdapterOne(List<TeJiaBean.ListEntity> mData, Context mContext) {
        this.mData = mData;
        this.mContext = mContext;
        options=new ImageOptions.Builder()
                .setAutoRotate(true)
                .build();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_tejia_one, null);
       MyViewHolder holder=new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        TeJiaBean.ListEntity listEntity = mData.get(position);
        holder.tvTitle.setText(listEntity.getTitle());
        holder.tvZhe.setText(listEntity.getDiscount()+"折");
        holder.tvPrice.setText("￥"+listEntity.getNow_price());
        holder.tvFPrice.setText("￥"+listEntity.getOrigin_price());
        x.image().bind(holder.ivTitle, NetConfig.TEJIA_ITEM_IAMHRVIEW_PATH+listEntity.getPic_url());
        holder.ivTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TeJiaBean.ListEntity listEntity = mData.get(position);
                String num_iid = listEntity.getNum_iid();
                Intent intent=new Intent(mContext,TeJiaDetailActivity.class);
                intent.putExtra("num_iid",num_iid);
                intent.putExtra("listEntity",listEntity);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{
        private TextView tvPrice,tvFPrice,tvTitle,tvZhe;
        private ImageView ivTitle;
        public MyViewHolder(View itemView) {
            super(itemView);
            tvFPrice= (TextView) itemView.findViewById(R.id.ltv_item_tejia_fprice);
            tvPrice= (TextView) itemView.findViewById(R.id.tv_item_tejia_price);
            tvTitle= (TextView) itemView.findViewById(R.id.tv_item_tejia_title);
            tvZhe= (TextView) itemView.findViewById(R.id.tv_item_tejia_zhe);

            ivTitle= (ImageView) itemView.findViewById(R.id.iv_item_tejia_title);
        }
    }
}
